<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>C 运算符 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../cprogramming/c-operators.html" />
<meta name="keywords" content="C 运算符">
<meta name="description" content="C 运算符   运算符是一种告诉编译器执行特定的数学或逻辑操作的符号。C 语言内置了丰富的运算符，并提供了以下类型的运算符：  算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 杂项运算符  本章将逐一介绍算术运算符、关系运算符、逻辑运算符、位运算符、赋值运算符和其他运算符。   算术运算符 下表显示了 C 语言支持的所有算术运算符。假设变量 A 的值为 10，变量 B 的值为 20，则：  运算符描述实例 +把两个操作数相加 ..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<!-- 导航栏 -->
<div class="container navigation">
	<div class="row">
		<div class="col nav">
			<ul class="pc-nav" id="runoob-detail-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JavaScript</a></li>
				<li><a href="javascript:void(0);" data-id="vue">Vue</a></li>
				<li><a href="javascript:void(0);" data-id="bootstrap">Bootstrap</a></li>
				<li><a href="../nodejs/nodejs-tutorial.html">NodeJS</a></li>
				<li><a href="../python3/python3-tutorial.html">Python3</a></li>
				<li><a href="../python/python-tutorial.html">Python2</a></li>
				<li><a href="../java/java-tutorial.html">Java</a></li>
				<li><a href="../cprogramming/c-tutorial.html">C</a></li>
				<li><a href="../cplusplus/cpp-tutorial.html">C++</a></li>
				<li><a href="../csharp/csharp-tutorial.html">C#</a></li>
				<li><a href="../go/go-tutorial.html">Go</a></li>
				<li><a href="../sql/sql-tutorial.html">SQL</a></li>
				<li><a href="../linux/linux-tutorial.html">Linux</a></li>
				<li><a href="../jquery/jquery-tutorial.html">jQuery</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<!--
			
				<li><a href="../w3cnote/knowledge-start.html" style="font-weight: bold;" onclick="_hmt.push(['_trackEvent', '星球', 'click', 'start'])" title="我的圈子">我的圈子</a></li>				
				<li><a href="javascript:;" class="runoob-pop">登录</a></li>
				-->
      		</ul>
			<ul class="mobile-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JS</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<li><a href="javascript:void(0)" class="search-reveal">Search</a> </li>
			</ul>
			
		</div>
	</div>
</div>

<div class="container sub-navigation sub-navigation-articles" style="display:none">
	<div class="row">
		<div class="col nav-sub">
		<ul id="python">
			<li class="cat-item"><a href="../python3/python3-tutorial.html">Python3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../python/python-tutorial.html">Python2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		<ul id="vue">
			<li class="cat-item"><a href="../vue3/vue3-tutorial.html">Vue3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../vue/vue-tutorial.html">vue2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>

		<ul id="bootstrap">
			<li class="cat-item"><a href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap/bootstrap-v2-tutorial.html">Bootstrap2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		</div>
	</div>
</div><!--  内容  -->
<div class="container main">
	<!-- 中间 -->
	<div class="row">
	
<div class="runoob-col-md2">
<div class="left-column">
	<div class="tab" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
	<i class="fa fa-list" aria-hidden="true"></i> 
	<span>C 教程</span>
	<a data-cate="157" href="javascript:void(0);" title="夜间模式"  id="moon"><i class="fa fa-moon-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;"></i></a>
	<a data-cate="157" style="display:none;" href="javascript:void(0);" title="日间模式"  id="sun" ><i class="fa fa-sun-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;line-height: 28px;
}"></i></a>

	</div>
	<div class="sidebar-box gallery-list">
		<div class="design" id="leftcolumn">
						<a target="_top" title="C 语言教程"  href="../cprogramming/c-tutorial.html" >
			C 语言教程			</a>
						<a target="_top" title="C 简介"  href="../cprogramming/c-intro.html" >
			C 简介			</a>
						<a target="_top" title="C 环境设置"  href="../cprogramming/c-environment-setup.html" >
			C 环境设置			</a>
						<a target="_top" title="C 程序结构"  href="../cprogramming/c-program-structure.html" >
			C 程序结构			</a>
						<a target="_top" title="C 基本语法"  href="../cprogramming/c-basic-syntax.html" >
			C 基本语法			</a>
						<a target="_top" title="C 数据类型"  href="../cprogramming/c-data-types.html" >
			C 数据类型			</a>
						<a target="_top" title="C 变量"  href="../cprogramming/c-variables.html" >
			C 变量			</a>
						<a target="_top" title="C 常量"  href="../cprogramming/c-constants.html" >
			C 常量			</a>
						<a target="_top" title="C 存储类"  href="../cprogramming/c-storage-classes.html" >
			C 存储类			</a>
						<a target="_top" title="C 运算符"  href="../cprogramming/c-operators.html" >
			C 运算符			</a>
						<a target="_top" title="C 判断"  href="../cprogramming/c-decision.html" >
			C 判断			</a>
						<a target="_top" title="C 循环"  href="../cprogramming/c-loops.html" >
			C 循环			</a>
						<a target="_top" title="C 函数"  href="../cprogramming/c-functions.html" >
			C 函数			</a>
						<a target="_top" title="C 作用域规则"  href="../cprogramming/c-scope-rules.html" >
			C 作用域规则			</a>
						<a target="_top" title="C 数组"  href="../cprogramming/c-arrays.html" >
			C 数组			</a>
			<a target="_top" title="C enum(枚举)" href="../cprogramming/c-enum.html">C enum(枚举)</a>			<a target="_top" title="C 指针"  href="../cprogramming/c-pointers.html" >
			C 指针			</a>
			<a target="_top" title="C 函数指针与回调函数" href="../cprogramming/c-fun-pointer-callback.html">C 函数指针与回调函数</a>			<a target="_top" title="C 字符串"  href="../cprogramming/c-strings.html" >
			C 字符串			</a>
						<a target="_top" title="C 结构体"  href="../cprogramming/c-structures.html" >
			C 结构体			</a>
						<a target="_top" title="C 共用体"  href="../cprogramming/c-unions.html" >
			C 共用体			</a>
						<a target="_top" title="C 位域"  href="../cprogramming/c-bit-fields.html" >
			C 位域			</a>
						<a target="_top" title="C typedef"  href="../cprogramming/c-typedef.html" >
			C typedef			</a>
						<a target="_top" title="C 输入 &#038; 输出"  href="../cprogramming/c-input-output.html" >
			C 输入 & 输出			</a>
						<a target="_top" title="C 文件读写"  href="../cprogramming/c-file-io.html" >
			C 文件读写			</a>
						<a target="_top" title="C 预处理器"  href="../cprogramming/c-preprocessors.html" >
			C 预处理器			</a>
						<a target="_top" title="C 头文件"  href="../cprogramming/c-header-files.html" >
			C 头文件			</a>
						<a target="_top" title="C 强制类型转换"  href="../cprogramming/c-type-casting.html" >
			C 强制类型转换			</a>
						<a target="_top" title="C 错误处理"  href="../cprogramming/c-error-handling.html" >
			C 错误处理			</a>
						<a target="_top" title="C 递归"  href="../cprogramming/c-recursion.html" >
			C 递归			</a>
						<a target="_top" title="C 可变参数"  href="../cprogramming/c-variable-arguments.html" >
			C 可变参数			</a>
						<a target="_top" title="C 内存管理"  href="../cprogramming/c-memory-management.html" >
			C 内存管理			</a>
						<a target="_top" title="C 命令行参数"  href="../cprogramming/c-command-line-arguments.html" >
			C 命令行参数			</a>
			
<a target="_top" title="C 排序算法" href="../cprogramming/c-sort-algorithm.html">C 排序算法</a>
<a target="_top" title="C 语言实例" href="../cprogramming/c-examples.html">C 语言实例 </a>
<a target="_top" title="C 语言经典100例" href="../cprogramming/c-100-examples.html"> C 经典100例 </a>
<br><h2 class="left">C <span class="left_h2">标准库</span></h2>			<a target="_top" title="C 标准库 &#8211; 参考手册"  href="../cprogramming/c-standard-library.html" >
			C 标准库 - 参考手册			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;assert.h&gt;"  href="../cprogramming/c-standard-library-assert-h.html" >
			C 标准库 - &lt;assert.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;ctype.h&gt;"  href="../cprogramming/c-standard-library-ctype-h.html" >
			C 标准库 - &lt;ctype.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;errno.h&gt;"  href="../cprogramming/c-standard-library-errno-h.html" >
			C 标准库 - &lt;errno.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;float.h&gt;"  href="../cprogramming/c-standard-library-float-h.html" >
			C 标准库 - &lt;float.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;limits.h&gt;"  href="../cprogramming/c-standard-library-limits-h.html" >
			C 标准库 - &lt;limits.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;locale.h&gt;"  href="../cprogramming/c-standard-library-locale-h.html" >
			C 标准库 - &lt;locale.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;math.h&gt;"  href="../cprogramming/c-standard-library-math-h.html" >
			C 标准库 - &lt;math.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;setjmp.h&gt;"  href="../cprogramming/c-standard-library-setjmp-h.html" >
			C 标准库 - &lt;setjmp.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;signal.h&gt;"  href="../cprogramming/c-standard-library-signal-h.html" >
			C 标准库 - &lt;signal.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;stdarg.h&gt;"  href="../cprogramming/c-standard-library-stdarg-h.html" >
			C 标准库 - &lt;stdarg.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;stddef.h&gt;"  href="../cprogramming/c-standard-library-stddef-h.html" >
			C 标准库 - &lt;stddef.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;stdio.h&gt;"  href="../cprogramming/c-standard-library-stdio-h.html" >
			C 标准库 - &lt;stdio.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;stdlib.h&gt;"  href="../cprogramming/c-standard-library-stdlib-h.html" >
			C 标准库 - &lt;stdlib.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;string.h&gt;"  href="../cprogramming/c-standard-library-string-h.html" >
			C 标准库 - &lt;string.h&gt;			</a>
						<a target="_top" title="C 标准库 &#8211; &lt;time.h&gt;"  href="../cprogramming/c-standard-library-time-h.html" >
			C 标准库 - &lt;time.h&gt;			</a>
						<a target="_top" title="C 语言测验"  href="../cprogramming/c-quiz.html" >
			C 语言测验			</a>
				
		</div>
	</div>	
</div>
</div>	<div class="col middle-column">
		
	
	<div class="article">
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../cprogramming/c-storage-classes.html" rel="prev"> C 存储类</a> </div>
			<div class="next-design-link"><a href="../cprogramming/c-decision.html" rel="next"> C 判断</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
<div class="article-heading-ad" style="display: block;">
<script async src=""
     crossorigin="anonymous"></script>
<!-- 728*90 固定 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="2147566827"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
		<div class="article-body">
		
			<div class="article-intro" id="content">
			
			
<h1>C <span class="color_h1">运算符</span></h1>

<div class="tutintro">
<p>运算符是一种告诉编译器执行特定的数学或逻辑操作的符号。C 语言内置了丰富的运算符，并提供了以下类型的运算符：</p>
<ul class="list">
<li>算术运算符</li>
<li>关系运算符</li>
<li>逻辑运算符</li>
<li>位运算符</li>
<li>赋值运算符</li>
<li>杂项运算符</li>
</ul>
<p>本章将逐一介绍算术运算符、关系运算符、逻辑运算符、位运算符、赋值运算符和其他运算符。</p>
</div>

<h2 class="tutheader">算术运算符</h2>
<p>下表显示了 C 语言支持的所有算术运算符。假设变量 <b>A</b> 的值为 10，变量 <b>B</b> 的值为 20，则：</p>
<table class="reference notranslate">
<tr><th style="width:10%">运算符</th><th style="width:55%;">描述</th><th>实例</th></tr>
<tr><td>+</td><td>把两个操作数相加</td><td> A + B 将得到 30</td></tr>
<tr><td>-</td><td>从第一个操作数中减去第二个操作数</td><td> A - B 将得到 -10</td></tr>
<tr><td>*</td><td>把两个操作数相乘</td><td> A * B 将得到 200</td></tr>
<tr><td>/</td><td>分子除以分母</td><td> B / A 将得到 2</td></tr>
<tr><td>%</td><td>取模运算符，整除后的余数</td><td> B % A 将得到 0</td></tr>
<tr><td>++</td><td>自增运算符，整数值增加 1</td><td> A++ 将得到 11</td></tr>
<tr><td>--</td><td>自减运算符，整数值减少 1</td><td> A-- 将得到 9</td></tr>
</table>
<h3>实例</h3>
<p>请看下面的实例，了解 C 语言中所有可用的算术运算符：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">21</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code"> ;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> + </span><span class="hl-identifier">b</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 1 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> - </span><span class="hl-identifier">b</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 2 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> * </span><span class="hl-identifier">b</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> / </span><span class="hl-identifier">b</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 4 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> % </span><span class="hl-identifier">b</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 5 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code">++;  </span><span class="hl-comment">// 赋值后再加 1 ，c 为 21，a 为 22</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 6 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code">--;  </span><span class="hl-comment">// 赋值后再减 1 ，c 为 22 ，a 为 21</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 7 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<pre>
Line 1 - c 的值是 31
Line 2 - c 的值是 11
Line 3 - c 的值是 210
Line 4 - c 的值是 2
Line 5 - c 的值是 1
Line 6 - c 的值是 21
Line 7 - c 的值是 22
</pre>
<p> 以下实例演示了 a++ 与 ++a 的区别：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code">++; 
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">先赋值后运算：</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 1 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 2 - a 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code">--; 
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 4 - a 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">先运算后赋值：</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = ++</span><span class="hl-identifier">a</span><span class="hl-code">; 
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 5 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 6 - a 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> = --</span><span class="hl-identifier">a</span><span class="hl-code">; 
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 7 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 8 - a 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>以上程序执行输出结果为：</p>
<pre>
先赋值后运算：
Line 1 - c 的值是 10
Line 2 - a 的值是 11
Line 3 - c 的值是 10
Line 4 - a 的值是 9
先运算后赋值：
Line 5 - c 的值是 11
Line 6 - a 的值是 11
Line 7 - c 的值是 9
Line 8 - a 的值是 9
</pre>
<h2 class="tutheader">关系运算符</h2>
<p>下表显示了 C 语言支持的所有关系运算符。假设变量 <b>A</b> 的值为 10，变量 <b>B</b> 的值为 20，则：</p>
<table class="reference notranslate">
<tr><th style="width:10%">运算符</th><th style="width:55%;">描述</th><th>实例</th></tr>
<tr><td>==</td><td>检查两个操作数的值是否相等，如果相等则条件为真。</td><td> (A == B) 为假。</td></tr>
<tr><td>!=</td><td>检查两个操作数的值是否相等，如果不相等则条件为真。</td><td> (A != B) 为真。</td></tr>
<tr><td>&gt;</td><td>检查左操作数的值是否大于右操作数的值，如果是则条件为真。</td><td> (A &gt; B) 为假。</td></tr>
<tr><td>&lt;</td><td>检查左操作数的值是否小于右操作数的值，如果是则条件为真。</td><td> (A &lt; B) 为真。</td></tr>
<tr><td>&gt;=</td><td>检查左操作数的值是否大于或等于右操作数的值，如果是则条件为真。</td><td> (A &gt;= B) 为假。</td></tr>
<tr><td>&lt;=</td><td>检查左操作数的值是否小于或等于右操作数的值，如果是则条件为真。</td><td> (A &lt;= B) 为真。</td></tr>
</table>
<h3>实例</h3>
<p>请看下面的实例，了解 C 语言中所有可用的关系运算符：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">21</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code"> ;
 
   </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> == </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 1 - a 等于 b</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">else</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 1 - a 不等于 b</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> &lt; </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 2 - a 小于 b</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">else</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 2 - a 不小于 b</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> &gt; </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - a 大于 b</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">else</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - a 不大于 b</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 改变 a 和 b 的值 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">5</span><span class="hl-code">;
   </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-number">20</span><span class="hl-code">;
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> &lt;= </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 4 - a 小于或等于 b</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> &gt;= </span><span class="hl-identifier">a</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 5 - b 大于或等于 a</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<pre>
Line 1 - a 不等于 b
Line 2 - a 不小于 b
Line 3 - a 大于 b
Line 4 - a 小于或等于 b
Line 5 - b 大于或等于 a
</pre>

<h2 class="tutheader">逻辑运算符</h2>
<p>下表显示了 C 语言支持的所有关系逻辑运算符。假设变量 <b>A</b> 的值为 1，变量 <b>B</b> 的值为 0，则：</p>
<table class="reference notranslate">
<tr><th style="width:10%">运算符</th><th style="width:55%;">描述</th><th>实例</th></tr>
<tr><td>&amp;&amp;</td><td>称为逻辑与运算符。如果两个操作数都非零，则条件为真。</td><td> (A &amp;&amp; B) 为假。</td></tr>
<tr><td>||</td><td>称为逻辑或运算符。如果两个操作数中有任意一个非零，则条件为真。</td><td> (A || B) 为真。</td></tr>
<tr><td>!</td><td>称为逻辑非运算符。用来逆转操作数的逻辑状态。如果条件为真则逻辑非运算符将使其为假。</td><td> !(A &amp;&amp; B) 为真。</td></tr>
</table>
<h3>实例</h3>
<p>请看下面的实例，了解 C 语言中所有可用的逻辑运算符：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">5</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-number">20</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code"> ;
 
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> &amp;&amp; </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 1 - 条件为真</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> || </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 2 - 条件为真</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 改变 a 和 b 的值 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">;
   </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> &amp;&amp; </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - 条件为真</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">else</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - 条件为假</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
   </span><span class="hl-reserved">if</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code"> !</span><span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-code"> &amp;&amp; </span><span class="hl-identifier">b</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">
   </span><span class="hl-brackets">{</span><span class="hl-code">
      </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 4 - 条件为真</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<pre>
Line 1 - 条件为真
Line 2 - 条件为真
Line 3 - 条件为假
Line 4 - 条件为真
</pre>

<h2 class="tutheader">位运算符</h2>
<p>位运算符作用于位，并逐位执行操作。&amp;、 | 和 ^ 的真值表如下所示：</p>
<table class="reference notranslate">
<tr><th style="width:20%">p</th><th style="width:20%">q</th><th style="width:20%">p &amp; q</th><th style="width:20%">p | q</th><th style="width:20%">p ^ q</th></tr>
<tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>0</td><td>1</td><td>0</td><td>1</td><td>1</td></tr>
<tr><td>1</td><td>1</td><td>1</td><td>1</td><td>0</td></tr>
<tr><td>1</td><td>0</td><td>0</td><td>1</td><td>1</td></tr>
</table>
<p>假设如果 A = 60，且 B = 13，现在以二进制格式表示，它们如下所示：</p>
<p>A = 0011 1100</p>
<p>B = 0000 1101</p>
<p>-----------------</p>
<p>A&amp;B = 0000 1100</p>
<p>A|B = 0011 1101</p>
<p>A^B = 0011 0001</p>
<p>~A&nbsp; = 1100 0011</p>
<p>下表显示了 C 语言支持的位运算符。假设变量 <b>A</b> 的值为 60，变量 <b>B</b> 的值为 13，则：</p>
<table class="reference">
<tr><th style="width:10%">运算符</th><th style="width:55%;">描述</th><th>实例</th></tr>
<tr><td>&amp;</td><td><p>按位与操作，按二进制位进行"与"运算。运算规则：</p>
<pre>0&amp;0=0;   
0&amp;1=0;    
1&amp;0=0;     
1&amp;1=1;</pre></td><td> (A &amp; B) 将得到 12，即为 0000 1100</td></tr>
<tr><td>|</td><td><p>按位或运算符，按二进制位进行"或"运算。运算规则：</p>
<pre>0|0=0;   
0|1=1;   
1|0=1;    
1|1=1;</pre>
</td><td> (A | B) 将得到 61，即为 0011 1101</td></tr>
<tr><td>^</td><td><p>异或运算符，按二进制位进行"异或"运算。运算规则：</p>
<pre>0^0=0;   
0^1=1;   
1^0=1;  
1^1=0;</pre>

</td><td> (A ^ B) 将得到 49，即为 0011 0001</td></tr>
<tr><td>~</td><td><p>取反运算符，按二进制位进行"取反"运算。运算规则：</p>
<pre>~1=-2;   
~0=-1;</pre></td><td> (~A ) 将得到 -61，即为 1100 0011，一个有符号二进制数的补码形式。</td></tr>
<tr><td>&lt;&lt;</td><td>二进制左移运算符。将一个运算对象的各二进制位全部左移若干位（左边的二进制位丢弃，右边补0）。</td><td> A &lt;&lt; 2 将得到 240，即为 1111 0000</td></tr>
<tr><td>&gt;&gt;</td><td>二进制右移运算符。将一个数的各二进制位全部右移若干位，正数左补0，负数左补1，右边丢弃。</td><td> A &gt;&gt; 2 将得到 15，即为 0000 1111</td></tr>
</table>
<h3>实例</h3>
<p>请看下面的实例，了解 C 语言中所有可用的位运算符：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
 
   </span><span class="hl-types">unsigned</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">60</span><span class="hl-code">;    </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 60 = 0011 1100 </span><span class="hl-mlcomment">*/</span><span class="hl-code">  
   </span><span class="hl-types">unsigned</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-number">13</span><span class="hl-code">;    </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 13 = 0000 1101 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-number">0</span><span class="hl-code">;           
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> &amp; </span><span class="hl-identifier">b</span><span class="hl-code">;       </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 12 = 0000 1100 </span><span class="hl-mlcomment">*/</span><span class="hl-code"> 
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 1 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> | </span><span class="hl-identifier">b</span><span class="hl-code">;       </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 61 = 0011 1101 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 2 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> ^ </span><span class="hl-identifier">b</span><span class="hl-code">;       </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 49 = 0011 0001 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> = ~</span><span class="hl-identifier">a</span><span class="hl-code">;          </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment">-61 = 1100 0011 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 4 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> &lt;&lt; </span><span class="hl-number">2</span><span class="hl-code">;     </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 240 = 1111 0000 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 5 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> &gt;&gt; </span><span class="hl-number">2</span><span class="hl-code">;     </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 15 = 0000 1111 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 6 - c 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<pre>
Line 1 - c 的值是 12
Line 2 - c 的值是 61
Line 3 - c 的值是 49
Line 4 - c 的值是 -61
Line 5 - c 的值是 240
Line 6 - c 的值是 15
</pre>

<h2 class="tutheader">赋值运算符</h2>
<p>下表列出了 C 语言支持的赋值运算符：</p>
<table class="reference notranslate">
<tr><th style="width:10%">运算符</th><th style="width:55%;">描述</th><th>实例</th></tr>
<tr><td>=</td><td>简单的赋值运算符，把右边操作数的值赋给左边操作数</td><td> C = A + B 将把 A + B 的值赋给 C</td></tr>
<tr><td>+=</td><td>加且赋值运算符，把右边操作数加上左边操作数的结果赋值给左边操作数</td><td> C += A 相当于 C = C + A</td></tr>
<tr><td>-=</td><td>减且赋值运算符，把左边操作数减去右边操作数的结果赋值给左边操作数</td><td> C -= A 相当于 C = C - A</td></tr>
<tr><td>*=</td><td>乘且赋值运算符，把右边操作数乘以左边操作数的结果赋值给左边操作数</td><td> C *= A 相当于 C = C * A</td></tr>
<tr><td>/=</td><td>除且赋值运算符，把左边操作数除以右边操作数的结果赋值给左边操作数</td><td> C /= A 相当于 C = C / A</td></tr>
<tr><td>%=</td><td>求模且赋值运算符，求两个操作数的模赋值给左边操作数</td><td> C %= A 相当于 C = C % A</td></tr>
<tr><td>&lt;&lt;=</td><td>左移且赋值运算符</td><td> C &lt;&lt;= 2 等同于  C = C &lt;&lt; 2</td></tr>
<tr><td>&gt;&gt;=</td><td>右移且赋值运算符</td><td> C &gt;&gt;= 2 等同于  C = C &gt;&gt; 2</td></tr>
<tr><td>&amp;=</td><td>按位与且赋值运算符</td><td> C &amp;= 2 等同于  C = C &amp; 2</td></tr>
<tr><td>^=</td><td>按位异或且赋值运算符</td><td> C ^= 2 等同于  C = C ^ 2</td></tr>
<tr><td>|=</td><td>按位或且赋值运算符</td><td> C |= 2 等同于  C = C | 2</td></tr>
</table>
<h3>实例</h3>
<p>请看下面的实例，了解 C 语言中所有可用的赋值运算符：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">21</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code"> ;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> =  </span><span class="hl-identifier">a</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 1 - =  运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> +=  </span><span class="hl-identifier">a</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 2 - += 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> -=  </span><span class="hl-identifier">a</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - -= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> *=  </span><span class="hl-identifier">a</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 4 - *= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> /=  </span><span class="hl-identifier">a</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 5 - /= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code">  = </span><span class="hl-number">200</span><span class="hl-code">;
   </span><span class="hl-identifier">c</span><span class="hl-code"> %=  </span><span class="hl-identifier">a</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 6 - %%= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> &lt;&lt;=  </span><span class="hl-number">2</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 7 - &lt;&lt;= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> &gt;&gt;=  </span><span class="hl-number">2</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 8 - &gt;&gt;= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> &amp;=  </span><span class="hl-number">2</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 9 - &amp;= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> ^=  </span><span class="hl-number">2</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 10 - ^= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">c</span><span class="hl-code"> |=  </span><span class="hl-number">2</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 11 - |= 运算符实例，c 的值 = %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">c</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<pre>
Line 1 - =  运算符实例，c 的值 = 21
Line 2 - += 运算符实例，c 的值 = 42
Line 3 - -= 运算符实例，c 的值 = 21
Line 4 - *= 运算符实例，c 的值 = 441
Line 5 - /= 运算符实例，c 的值 = 21
Line 6 - %= 运算符实例，c 的值 = 11
Line 7 - &lt;&lt;= 运算符实例，c 的值 = 44
Line 8 - &gt;&gt;= 运算符实例，c 的值 = 11
Line 9 - &amp;= 运算符实例，c 的值 = 2
Line 10 - ^= 运算符实例，c 的值 = 0
Line 11 - |= 运算符实例，c 的值 = 2
</pre>

<h2 class="tutheader">杂项运算符 &map; sizeof &amp; 三元</h2>
<p>下表列出了 C 语言支持的其他一些重要的运算符，包括 <b>sizeof</b> 和 <b>? :</b>。</p>
<table class="reference">
<tr><th style="width:10%">运算符</th><th style="width:55%;">描述</th><th>实例</th></tr>
<tr>
<td>sizeof()</td><td>返回变量的大小。</td><td>sizeof(a) 将返回 4，其中 a 是整数。</td>
</tr>
<tr>
<td>&amp;</td><td>返回变量的地址。</td><td>&amp;a; 将给出变量的实际地址。</td>
</tr>
<tr>
<td>*</td><td>指向一个变量。</td><td>*a; 将指向一个变量。</td>
</tr>
<tr>
<td>? :</td><td>条件表达式</td><td>如果条件为真 ? 则值为 X : 否则值为 Y</td>
</tr>
</table>
<h3>实例</h3>
<p>请看下面的实例，了解 C 语言中所有可用的杂项运算符：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">4</span><span class="hl-code">;
   </span><span class="hl-types">short</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code">;
   </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code">* </span><span class="hl-identifier">ptr</span><span class="hl-code">;
 
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> sizeof 运算符实例 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 1 - 变量 a 的大小 = %lu</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-reserved">sizeof</span><span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 2 - 变量 b 的大小 = %lu</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-reserved">sizeof</span><span class="hl-brackets">(</span><span class="hl-identifier">b</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Line 3 - 变量 c 的大小 = %lu</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-reserved">sizeof</span><span class="hl-brackets">(</span><span class="hl-identifier">c</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> &amp; 和 * 运算符实例 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">ptr</span><span class="hl-code"> = &amp;</span><span class="hl-identifier">a</span><span class="hl-code">;    </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 'ptr' 现在包含 'a' 的地址 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">a 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">a</span><span class="hl-brackets">)</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">*ptr 是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, *</span><span class="hl-identifier">ptr</span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-mlcomment">/*</span><span class="hl-mlcomment"> 三元运算符实例 </span><span class="hl-mlcomment">*/</span><span class="hl-code">
   </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-code"> == </span><span class="hl-number">1</span><span class="hl-brackets">)</span><span class="hl-code"> ? </span><span class="hl-number">20</span><span class="hl-code">: </span><span class="hl-number">30</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">b 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-code"> == </span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code"> ? </span><span class="hl-number">20</span><span class="hl-code">: </span><span class="hl-number">30</span><span class="hl-code">;
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">b 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-identifier">b</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<pre>
Line 1 - 变量 a 的大小 = 4
Line 2 - 变量 b 的大小 = 2
Line 3 - 变量 c 的大小 = 8
a 的值是 4
*ptr 是 4
b 的值是 30
b 的值是 20
</pre>

<h2 class="tutheader">C 中的运算符优先级</h2>
<p>运算符的优先级确定表达式中项的组合。这会影响到一个表达式如何计算。某些运算符比其他运算符有更高的优先级，例如，乘除运算符具有比加减运算符更高的优先级。</p>
<p>例如 x = 7 + 3 * 2，在这里，x 被赋值为 13，而不是 20，因为运算符 * 具有比 + 更高的优先级，所以首先计算乘法 3*2，然后再加上 7。</p>
 <p>下表将按运算符优先级从高到低列出各个运算符，具有较高优先级的运算符出现在表格的上面，具有较低优先级的运算符出现在表格的下面。在表达式中，较高优先级的运算符会优先被计算。</p>
<table class="reference notranslate">
<tr> <th>类别&nbsp;</th> <th>运算符&nbsp;</th><th>结合性&nbsp;</th> </tr> 
<tr> <td>后缀&nbsp;</td><td>() [] -&gt; .  ++   - - &nbsp;</td> <td>从左到右&nbsp;</td> </tr>
<tr> <td>一元&nbsp;</td> <td>+  -   !  ~  ++  - -   (type)*  &amp;  sizeof&nbsp;</td> <td>从右到左&nbsp;</td></tr> 
<tr> <td>乘除&nbsp;</td> <td>*  /  %&nbsp;</td><td>从左到右&nbsp;</td> </tr> 
<tr> <td>加减&nbsp;</td><td>+  -&nbsp;</td> <td>从左到右&nbsp;</td> </tr>
<tr> <td>移位&nbsp;</td> <td>&lt;&lt; &gt;&gt;&nbsp;</td> <td>从左到右&nbsp;</td> </tr> 
<tr> <td>关系&nbsp;</td><td>&lt; &lt;=  &gt; &gt;=&nbsp;</td> <td>从左到右&nbsp;</td> </tr>
<tr> <td>相等&nbsp;</td> <td>==  !=&nbsp;</td> <td>从左到右&nbsp;</td> </tr> 
<tr> <td>位与 AND&nbsp;</td><td>&amp;&nbsp;</td> <td>从左到右&nbsp;</td> </tr> 
<tr> <td>位异或 XOR&nbsp;</td> <td>^&nbsp;</td> <td>从左到右&nbsp;</td></tr> 
<tr> <td>位或 OR&nbsp;</td> <td>|&nbsp;</td> <td>从左到右&nbsp;</td></tr> 
<tr> <td>逻辑与 AND&nbsp;</td><td>&amp;&amp;&nbsp;</td> <td>从左到右&nbsp;</td></tr>
<tr><td>逻辑或 OR&nbsp;</td> <td>||&nbsp;</td> <td>从左到右&nbsp;</td></tr> 
<tr> <td>条件&nbsp;</td><td>?:&nbsp;</td> <td>从右到左&nbsp;</td> </tr>
<tr><td>赋值&nbsp;</td> <td>=  +=  -=  *=  /=  %=&gt;&gt;=  &lt;&lt;=  &amp;=  ^=   |=&nbsp;</td><td>从右到左&nbsp;</td></tr>
<tr> <td>逗号&nbsp;</td> <td>,&nbsp;</td> <td>从左到右&nbsp;</td></tr> 
</table>
<h3>实例</h3>
<p>请看下面的实例，了解 C 语言中运算符的优先级：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-prepro">#include</span><span class="hl-prepro"> </span><span class="hl-quotes">&lt;</span><span class="hl-string">stdio.h</span><span class="hl-quotes">&gt;</span><span class="hl-prepro"></span><span class="hl-code">
 
</span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
</span><span class="hl-brackets">{</span><span class="hl-code">
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">a</span><span class="hl-code"> = </span><span class="hl-number">20</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-number">10</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">c</span><span class="hl-code"> = </span><span class="hl-number">15</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">d</span><span class="hl-code"> = </span><span class="hl-number">5</span><span class="hl-code">;
   </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">e</span><span class="hl-code">;
 
   </span><span class="hl-identifier">e</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-code"> + </span><span class="hl-identifier">b</span><span class="hl-brackets">)</span><span class="hl-code"> * </span><span class="hl-identifier">c</span><span class="hl-code"> / </span><span class="hl-identifier">d</span><span class="hl-code">;      </span><span class="hl-comment">// ( 30 * 15 ) / 5</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">(a + b) * c / d 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">,  </span><span class="hl-identifier">e</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">e</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-code"> + </span><span class="hl-identifier">b</span><span class="hl-brackets">)</span><span class="hl-code"> * </span><span class="hl-identifier">c</span><span class="hl-brackets">)</span><span class="hl-code"> / </span><span class="hl-identifier">d</span><span class="hl-code">;    </span><span class="hl-comment">// (30 * 15 ) / 5</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">((a + b) * c) / d 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> ,  </span><span class="hl-identifier">e</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">e</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-identifier">a</span><span class="hl-code"> + </span><span class="hl-identifier">b</span><span class="hl-brackets">)</span><span class="hl-code"> * </span><span class="hl-brackets">(</span><span class="hl-identifier">c</span><span class="hl-code"> / </span><span class="hl-identifier">d</span><span class="hl-brackets">)</span><span class="hl-code">;   </span><span class="hl-comment">// (30) * (15/5)</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">(a + b) * (c / d) 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code">,  </span><span class="hl-identifier">e</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
 
   </span><span class="hl-identifier">e</span><span class="hl-code"> = </span><span class="hl-identifier">a</span><span class="hl-code"> + </span><span class="hl-brackets">(</span><span class="hl-identifier">b</span><span class="hl-code"> * </span><span class="hl-identifier">c</span><span class="hl-brackets">)</span><span class="hl-code"> / </span><span class="hl-identifier">d</span><span class="hl-code">;     </span><span class="hl-comment">//  20 + (150/5)</span><span class="hl-comment"></span><span class="hl-code">
   </span><span class="hl-identifier">printf</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">a + (b * c) / d 的值是 %d</span><span class="hl-special">\</span><span class="hl-string">n</span><span class="hl-quotes">&quot;</span><span class="hl-code"> ,  </span><span class="hl-identifier">e</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;
  
   </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-number">0</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<pre>
(a + b) * c / d 的值是 90
((a + b) * c) / d 的值是 90
(a + b) * (c / d) 的值是 90
a + (b * c) / d 的值是 50
</pre>			<!-- 其他扩展 -->
						
			</div>
			
		</div>
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../cprogramming/c-storage-classes.html" rel="prev"> C 存储类</a> </div>
			<div class="next-design-link"><a href="../cprogramming/c-decision.html" rel="next"> C 判断</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
		<!-- 笔记列表 -->
		<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div class="title" id="comments">
	<h2 class="">
    <div class="altblock">
				<i style="font-size:28px;margin-top: 8px;" class="fa fa-plus-square" aria-hidden="true"></i>
		    </div>
    <span class="mw-headline" id="qa_headline">11  篇笔记</span>
	<span class="mw-headline" id="user_add_note" style="float:right;line-height: 62px;padding-right: 14px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  写笔记</span>
    </h2>
</div>

<div id="postcomments"  style="display:none;" >
	<ol class="commentlist">
		<li class="comment even thread-even depth-1" id="comment-17502"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;sfvx</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;268***0313@qq.com</p></div><div id="runoobvote-id-17502" data-commid = "17502" class="upvotejs"><a class="upvote"></a> <span class="count">405</span></div></div><div class="comt-main" id="div-comment-17502"><p>利用异或 <span class="marked">^</span> 来交换两个数的值，而且不引入其他变量。</p>


<pre>unsigned int a=60;  //0011 1100
unsigned int b=13;  //0000 1101
a=a^b;              //a=a^b=0011 0001
b=a^b;              //b=a^b=0011 1100  相当于b1=(a^b)^b
a=a^b;              //a=a^b=0000 1101  相当于a1=(a^b)^((a^b)^b)</pre>


<p>实例</p>

<pre>#include&lt;stdio.h&gt;

int main( )
{
    unsigned int a=60;         //0011 1100
    unsigned int b=13;         //0000 1101
    printf("a=%d,b=%d",a,b);   //输出a，b的值
    printf("\n");
    a=a^b;                     //a=a^b=0011 0001
    b=a^b;                     //b=a^b=0011 1100
    a=a^b;                     //a=a^b=0000 1101
    printf("a=%d,b=%d",a,b);   //输出a，b的值
}</pre>
<p>结果：</p>


<pre>a=60，b=13；
a=13，b=60;</pre>



<p>仅用一行代码实现的方法:</p>

<pre>a^=b^=a^=b;</pre>
<p>其等价于:</p>

<pre>a=a^b;
b=a^b;
a=a^b;</pre><p>
当然，这种利用位运算的交换方法只适用于整型变量，不能用于浮点型变量!</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">sfvx</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;sfvx</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;268***0313@qq.com</p></div></span>6年前 (2017-09-13)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-19827"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;BeanShell</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;286***384@qq.com</p></div><div id="runoobvote-id-19827" data-commid = "19827" class="upvotejs"><a class="upvote"></a> <span class="count">172</span></div></div><div class="comt-main" id="div-comment-19827"><p>利用位与 <span class="marked">&</span> 运算，判断一个整数是否是2的整数次幂。</p>
<p>二进制数的位权是以2为底的幂，如果一个整数 m 是 2 的 n 次幂，那么转换为二进制之后只有最高位为 1，其余位置为 0，再观察 m-1 转换为二进制后的形式以及 m&(m-1) 的结果，例如：</p>


<pre>2 --&gt; 0000 0010        1 --&gt; 0000 0001        2&amp;1 --&gt; 0000 0010 &amp; 0000 0001 = 0
4 --&gt; 0000 0100        3 --&gt; 0000 0011        4&amp;3 --&gt; 0000 0100 &amp; 0000 0011 = 0
8 --&gt; 0000 1000        7 --&gt; 0000 0111        8&amp;7 --&gt; 0000 1000 &amp; 0000 0111 = 0</pre>


<p>可以看出所有的 1 完美的错过了，根据位与的特点可知 m&(m-1) 的结果为 0。</p>

<p>如果整数 m 不是 2 的 n 次幂，结果会怎样呢？例如 m=9 时：</p>

<pre>9 --&gt; 0000 1001        8 --&gt; 0000 1000        9&amp;8 --&gt; 0000 1001 &amp; 0000 1000 != 0</pre>

<p>利用这一特点，即可判断一个整数是否是2的整数次幂。</p>

<p>示例：</p>


<pre>int func(int num)
{
    return ((num &gt; 0) &amp;&amp; ((num &amp; (num - 1)) == 0));//2的n次幂大于0
}</pre>


<p>返回值为 1，则输入的正整数为 2 的整数次幂，返回值为 0 则不是。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">BeanShell</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;BeanShell</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;286***384@qq.com</p></div></span>6年前 (2017-11-04)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-28353"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;布克F91</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;335***443@qq.com</p></div><div id="runoobvote-id-28353" data-commid = "28353" class="upvotejs"><a class="upvote"></a> <span class="count">88</span></div></div><div class="comt-main" id="div-comment-28353"><p data-title="C 取余运算说明"><strong>对取余运算的说明</strong></p>

<p>取余，也就是求余数，使用的运算符是 <span class="marked">%</span>。C 语言中的取余运算只能针对整数，也就是说，<span class="marked">%</span> 的两边都必须是整数，不能出现小数，否则编译器会报错。</p>

<p>另外，余数可以是正数也可以是负数，由 <span class="marked">%</span> 左边的整数决定：</p>
<ul><li>
如果 % 左边是正数，那么余数也是正数；</li><li>
如果 % 左边是负数，那么余数也是负数；</li></ul>
<p>请看下面的例子：</p>

<pre>#include &lt;stdio.h&gt;

int main()
{
    printf( "100%%12=%d \n100%%-12=%d \n-100%%12=%d \n-100%%-12=%d \n", 100%12, 100%-12, -100%12, -100%-12 );
    return 0;
}</pre>

<p>运行结果：</p>
<pre>100%12=4
100%-12=4
-100%12=-4
-100%-12=-4 </pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="../note/28353">布克F91</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;布克F91</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;335***443@qq.com</p></div></span>5年前 (2018-06-13)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-29210"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;forspy</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;qiu***@126.com</p></div><div id="runoobvote-id-29210" data-commid = "29210" class="upvotejs"><a class="upvote"></a> <span class="count">38</span></div></div><div class="comt-main" id="div-comment-29210"><p>对于 2 的幂指数的详细程序</p>

<pre>#include &lt;stdio.h&gt;

int num;
int func(int num)
{
    if ((num&gt;0)&amp;&amp;(num&amp;(num-1))==0)
    {
        printf("%d是2的整数次幂",num);
    }
    else
    {
        printf("%d不是2的整数次幂",num);
    }
    return((num&gt;0)&amp;&amp;(num&amp;(num-1))==0);
}

int main()
{
    printf("请输入要查询的数\n");
    scanf("%d",&amp;num);
    func(num);
}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">forspy</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;forspy</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;qiu***@126.com</p></div></span>5年前 (2018-07-06)</div></div></li><!-- #comment-## -->
<li class="comment byuser comment-author-tianqixin even thread-even depth-1" id="comment-29685"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;RES</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;432***967@qq.com</p></div><div id="runoobvote-id-29685" data-commid = "29685" class="upvotejs"><a class="upvote"></a> <span class="count">29</span></div></div><div class="comt-main" id="div-comment-29685"><p><strong>不同长度的数据进行位运算</strong></p>
<p>如果两个不同长度的数据进行位运算时，系统会将二者按右端对齐，然后进行位运算。</p>

<p>以“与”运算为例说明如下：我们知道在 C 语言中 long 型占 4 个字节，int 型占 2 个字节，如果一个 long 型数据与一个 int 型数据进行“与”运算，右端对齐后，左边不足的位依下面三种情况补足:</p>
<ul><li>
（1）如果整型数据为正数，左边补 16 个 0。
</li><li>
（2）如果整型数据为负数，左边补 16 个 1。
</li><li>
（3）如果整形数据为无符号数，左边也补 16 个 0。
</li></ul>
<p>如：<span class="marked">long a=123;int b=1;</span> 计算 <span class="marked">a & b</span>。</p>

 

<p>如：<span class="marked">long a=123;int b=-1;</span> 计算 <span class="marked">a & b</span>。</p>

 

<p>如：<span class="marked">long a=123; unsigned int b=1;</span> 计算 <span class="marked">a & b</span>。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">RES</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;RES</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;432***967@qq.com</p></div></span>5年前 (2018-07-16)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-34429"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;荒城梦呓</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;449***19@qq.com</p></div><div id="runoobvote-id-34429" data-commid = "34429" class="upvotejs"><a class="upvote"></a> <span class="count">48</span></div></div><div class="comt-main" id="div-comment-34429"><p data-title="| 和 ||，& 和 && 的区别"><strong>| 和 ||，& 和 && 的区别</strong></p>

<p>我们将 <strong>||</strong> 和 <strong>&&</strong> 定义为逻辑运算符，而 <strong>|</strong> 和 <strong>&</strong> 定义为位运算符。</p>

<p><span class="marked">&&</span> 如果两个操作数都非零，则条件为真；</p>
<p><span class="marked">||</span> 如果两个操作数中有任意一个非零，则条件为真。</p>

<p><span class="marked">&</span> 按位与操作，按二进制位进行"<strong>与</strong>"运算。运算规则：（有 0 则为 0）</p>

<pre>0&amp;0=0;   
0&amp;1=0;    
1&amp;0=0;     
1&amp;1=1;</pre>

<p><span class="marked">|</span> 按位或运算符，按二进制位进行"<strong>或</strong>"运算。运算规则：（有 1 则为 1）</p>

<pre>0|0=0;   
0|1=1;   
1|0=1;    
1|1=1;</pre>
<p><strong>那么，问题来了，在判断语句中，用 | 还是 ||，& 还是 &&？</strong></p>

<p>判断语句中为布尔类型，值只有 true 和 false（如果变量值为 0 就是 false，否则为 true）</p>

<pre>举个例子，a=1 b=2
所以 a&gt;0 这个值为true    b&gt;1 这个值为true     b&gt;2 这个值为 false
如 if(a&gt;0&amp;b&gt;1)  我们可以得出 if(true&amp;true)，条件成立（true不为0，所以true&amp;true不为0）
如 if(a&gt;0&amp;&amp;b&gt;1)  我们可以得出 if(true&amp;&amp;true),条件成立（&amp;&amp;两边操作数都非零，所以条件成立）
如 if(b&gt;2&amp;a&gt;0) 我们可以得出 if(false&amp;true)，条件不成立（false为0，false&amp;true为0，条件不成立）
如 if(b&gt;2&amp;&amp;a&gt;0) 我们可以得出 if(false&amp;&amp;a&gt;0)，条件不成立（&amp;&amp;左侧为false，&amp;&amp;运算到此结束，条件不成立）</pre>

<p>可以看出 & 和 && 在判断语句中都可以实现“和”这个功能，不过区别在于 & 两边都运算，而 && 先算 && 左侧，若左侧为 false 那么右侧就不运算了。因此从效率上来说，判断语句中推荐使用 &&（换句话就是逻辑运算就老老实实用逻辑运算符，不然它为啥叫逻辑运算符呢？）</p>

<p>而 | 和 || 的比较与上类似，不做赘述。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="../note/34429">荒城梦呓</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;荒城梦呓</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;449***19@qq.com</p></div></span>5年前 (2018-08-26)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-38255"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;chiu</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;amo***@126.com</p></div><div id="runoobvote-id-38255" data-commid = "38255" class="upvotejs"><a class="upvote"></a> <span class="count">56</span></div></div><div class="comt-main" id="div-comment-38255"><p><strong>a++ 与 ++a 区别在于一个后加，一个先加</strong>。</p>
<p>a++ 输出 a 的值再自加，缓存 a 自加后的结果，用于下次进行与 a 相关的计算。</p>
<p>++a 则相当于 a+1。</p>

<pre>#include &lt;stdio.h&gt;

int main(int argc, char **argv) {
    int a=100;
    int b=50;
//    b++;
    printf("%d,%d\n",a++,++a);
    printf("%d,%d",b++,++b);
    return 0;
}</pre>
<p>运行后输出：</p>

<pre>101,102
51,52</pre>

<p>若不注释 <strong>b++</strong>：</p>

<pre>int main(int argc, char **argv) {
    int a=100;
    int b=50;
    b++;
    printf("%d,%d\n",a++,++a);
    printf("%d,%d",b++,++b);
    return 0;
}</pre>
<p>则结果为：</p>

<pre>101,102
52,53</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">chiu</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;chiu</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;amo***@126.com</p></div></span>4年前 (2018-12-21)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-43612"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;你哈怂</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;853***635@qq.com</p></div><div id="runoobvote-id-43612" data-commid = "43612" class="upvotejs"><a class="upvote"></a> <span class="count">176</span></div></div><div class="comt-main" id="div-comment-43612"><p>运算符优先级：</p>
<pre>括号成员是老大;      // 括号运算符 []() 成员运算符.  -&gt;

全体单目排老二;      // 所有的单目运算符比如++、 --、 +(正)、 -(负) 、指针运算*、&amp;

乘除余三,加减四;    // 这个"余"是指取余运算即%

移位五，关系六;     // 移位运算符：&lt;&lt; &gt;&gt; ，关系：&gt; &lt; &gt;= &lt;= 等

等与不等排行七;     // 即 == 和 !=

位与异或和位或;     // 这几个都是位运算: 位与(&amp;)异或(^)位或(|)    

"三分天下"八九十;  

逻辑与，逻辑或;    // 逻辑运算符: || 和 &amp;&amp;

十一十二紧挨着;    // 注意顺序: 优先级(||)  底于 优先级(&amp;&amp;) 

条件只比赋值高,    // 三目运算符优先级排到 13 位只比赋值运算符和 "," 高

逗号运算最低级!    //逗号运算符优先级最低 </pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">你哈怂</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;你哈怂</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;853***635@qq.com</p></div></span>4年前 (2019-06-13)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-48752"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;已经不认识真了</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;and***_e@163.com</p></div><div id="runoobvote-id-48752" data-commid = "48752" class="upvotejs"><a class="upvote"></a> <span class="count">24</span></div></div><div class="comt-main" id="div-comment-48752"><p>一句话系列。</p><p>逻辑是将两个操作值转换成Boolean进行操作。</p><p>逻辑与：双真真（双真为真，下同）；</p><p>逻辑或：单真真；</p><p>逻辑非：取反；</p><p><b>没有说明的情况都为假（0）</b>。</p><p></p><p>按位是将两个操作值转换成二进制然后<b>逐位</b>进行操作。</p><p>按位与：双真真；</p><p>按位或：有真真（有一个真即为真，两个真的情况也属于有一个真）；</p><p>按位异或：单真真（区别于有真真，两个真的情况不属于单真）；</p><p><b>按位是二进制逐位操作，未说明的皆假。</b></p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">已经不认识真了</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;已经不认识真了</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;and***_e@163.com</p></div></span>3年前 (2019-11-24)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-52701"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;hellolsk</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;592***785@qq.com</p></div><div id="runoobvote-id-52701" data-commid = "52701" class="upvotejs"><a class="upvote"></a> <span class="count">44</span></div></div><div class="comt-main" id="div-comment-52701"><p>c语言中运算符优先级的总结：</p><p><b>初等运算符&gt;单目运算符&gt;算术运算符&gt;关系运算符&gt;逻辑运算符&gt;条件运算符&gt;赋值运算符</b></p>
<pre>初等运算符有：（）、[ ]、-&gt;、.  (后两者均为结构体成员运算符)；
单目运算符有：！、~、++、--、sizeof、&amp;、*；
算术运算符有：*、/、+、-、&lt;&lt;、&gt;&gt;;
关系运算符有：&lt;、&lt;=、&gt;、&gt;=、==、!=、&amp;、^、|；(此栏排列仍有优先级顺序哦);
逻辑运算符有：&amp;&amp;、||；
条件运算符有：？：（即三目运算符）;
赋值运算符有：=、+=、-=、*=、/=、%=、&gt;&gt;=、&lt;&lt;=；等</pre>
<p>另外，单目运算符的优先级都高于双目运算符。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">hellolsk</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;hellolsk</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;592***785@qq.com</p></div></span>3年前 (2020-04-15)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-61426"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Long</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;uca***long@gmail.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://www.jianshu.com/p/6c518e7b4690">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-61426" data-commid = "61426" class="upvotejs"><a class="upvote"></a> <span class="count">51</span></div></div><div class="comt-main" id="div-comment-61426"><p>在计算机中，负数以其正值的补码形式表达</p>
<p>
什么叫补码呢？这得从原码，反码说起。</p>
<p>
<strong>原码：</strong>一个整数，按照绝对值大小转换成的二进制数，称为原码。</p>
<p>
比如 <span class="marked">00000000 00000000 00000000 00000101</span> 是 <strong>5</strong> 的原码。</p>
<p>
<strong>反码：</strong>将二进制数按位取反，所得的新二进制数称为原二进制数的反码。</p>

<p>取反操作指：原为 1，得 0；原为 0，得 1。（1 变 0; 0 变 1）</p>
<p>
比如：将 00000000 00000000 00000000 00000101 每一位取反，得 11111111 11111111 11111111 11111010。</p>

<p>称：11111111 11111111 11111111 11111010是 00000000 00000000 00000000 00000101 的反码。</p>
<p>
反码是相互的，所以也可称：</p>
<p>
11111111 11111111 11111111 11111010 和00000000 00000000 00000000 00000101 互为反码。</p>
<p>
<strong>补码：</strong>反码加1称为补码。</p>
<p>
也就是说，要得到一个数的补码，先得到反码，然后将反码加上 1，所得数称为补码。</p>
<p>
比如：00000000 00000000 00000000 00000101 的反码是：11111111 11111111 11111111 11111010。</p>
<p>
那么，补码为：</p>
<p>
11111111 11111111 11111111 11111010 + 1 = 11111111 11111111 11111111 11111011</p>
<p>
所以，-5 在计算机中表达为：11111111 11111111 11111111 11111011。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">Long</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Long</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;uca***long@gmail.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://www.jianshu.com/p/6c518e7b4690">&nbsp;&nbsp;参考地址</a></p></div></span>2年前 (2021-02-19)</div></div></li><!-- #comment-## -->
	</ol>
	<div class="pagenav">
			</div>
</div>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style="display:none; padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='9510' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  9510;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 9510, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":9510},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
		<div class="sidebar-box ">
				

<style>	
.responsive_ad1 { display:none; }
@media(min-width: 800px) { .responsive_ad1 {  display:block;margin:0 auto;} }
</style>
<div id="ad-336280" >

<script async src=""
     crossorigin="anonymous"></script>
<!-- 移动版 自动调整 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="1691338467"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
				</div>
		
	</div>
</div>
	

<!-- 右边栏 -->
<div class="fivecol last right-column">

<style>
.sidebar-tree .double-li {
    width:300px;
}
.sidebar-tree .double-li li {
    width: 44%;
    line-height: 1.5em;
    border-bottom: 1px solid #ccc;
    float: left;
    display: inline;
}
</style>

    
        <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here" style="margin: 0 auto;">
            <a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;"> <i class="fa fa-list" aria-hidden="true"></i> 分类导航</a>
        </div>
    <div class="sidebar-box sidebar-cate">
        
        <div class="sidebar-tree" >
            <ul><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> HTML / CSS</a><ul class="double-li"><li><a title="HTML 教程" href="../html/html-tutorial.html">HTML 教程</a></li><li><a title="HTML5 教程" href="../html/html5-intro.html">HTML5 教程</a></li><li><a title="CSS 教程" href="../css/css-tutorial.html">CSS 教程</a></li><li><a title="CSS3 教程" href="../css3/css3-tutorial.html">CSS3 教程</a></li><li><a title="Bootstrap3 教程" href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程</a></li><li><a title="Bootstrap4 教程" href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程</a></li><li><a title="Bootstrap5 教程" href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程</a></li><li><a title="Font Awesome 教程" href="../font-awesome/fontawesome-tutorial.html">Font Awesome 教程</a></li><li><a title="Foundation 教程" href="../foundation/foundation-tutorial.html">Foundation 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> JavaScript</a><ul class="double-li"><li><a title="JavaScript 教程" href="../js/js-tutorial.html">JavaScript 教程</a></li><li><a title="HTML DOM 教程" href="../htmldom/htmldom-tutorial.html">HTML DOM 教程</a></li><li><a title="jQuery 教程" href="../jquery/jquery-tutorial.html">jQuery 教程</a></li><li><a title="AngularJS 教程" href="../angularjs/angularjs-tutorial.html">AngularJS 教程</a></li><li><a title="AngularJS2 教程" href="../angularjs2/angularjs2-tutorial.html">AngularJS2 教程</a></li><li><a title="Vue.js 教程" href="../vue2/vue-tutorial.html">Vue.js 教程</a></li><li><a title="Vue3 教程" href="../vue3/vue3-tutorial.html">Vue3 教程</a></li><li><a title="React 教程" href="../react/react-tutorial.html">React 教程</a></li><li><a title="TypeScript 教程" href="../typescript/ts-tutorial.html">TypeScript 教程</a></li><li><a title="jQuery UI 教程" href="../jqueryui/jqueryui-tutorial.html">jQuery UI 教程</a></li><li><a title="jQuery EasyUI 教程" href="../jeasyui/jqueryeasyui-tutorial.html">jQuery EasyUI 教程</a></li><li><a title="Node.js 教程" href="../nodejs/nodejs-tutorial.html">Node.js 教程</a></li><li><a title="AJAX 教程" href="../ajax/ajax-tutorial.html">AJAX 教程</a></li><li><a title="JSON 教程" href="../json/json-tutorial.html">JSON 教程</a></li><li><a title="Echarts 教程" href="../echarts/echarts-tutorial.html">Echarts 教程</a></li><li><a title="Chart.js 教程" href="../chartjs/chartjs-tutorial.html">Chart.js 教程</a></li><li><a title="Highcharts 教程" href="../highcharts/highcharts-tutorial.html">Highcharts 教程</a></li><li><a title="Google 地图 教程" href="../googleapi/google-maps-basic.html">Google 地图 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 服务端</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="Python2.x 教程" href="../python/python-tutorial.html">Python2.x 教程</a></li><li><a title="Linux 教程" href="../linux/linux-tutorial.html">Linux 教程</a></li><li><a title="Docker 教程" href="../docker/docker-tutorial.html">Docker 教程</a></li><li><a title="Ruby 教程" href="../ruby/ruby-tutorial.html">Ruby 教程</a></li><li><a title="Java 教程" href="../java/java-tutorial.html">Java 教程</a></li><li><a title="C 教程" href="../c/c-tutorial.html">C 教程</a></li><li><a title="C++ 教程" href="../cplusplus/cpp-tutorial.html">C++ 教程</a></li><li><a title="Perl 教程" href="../perl/perl-tutorial.html">Perl 教程</a></li><li><a title="Servlet 教程" href="../servlet/servlet-tutorial.html">Servlet 教程</a></li><li><a title="JSP 教程" href="../jsp/jsp-tutorial.html">JSP 教程</a></li><li><a title="Lua 教程" href="../lua/lua-tutorial.html">Lua 教程</a></li><li><a title="Rust 教程" href="../rust/rust-tutorial.html">Rust 教程</a></li><li><a title="Scala 教程" href="../scala/scala-tutorial.html">Scala 教程</a></li><li><a title="Go 教程" href="../go/go-tutorial.html">Go 教程</a></li><li><a title="PHP 教程" href="../php/php-tutorial.html">PHP 教程</a></li><li><a title="数据结构与算法" href="../data-structures/data-structures-tutorial.html">数据结构与算法</a></li><li><a title="Django 教程" href="../django/django-tutorial.html">Django 教程</a></li><li><a title="Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html">Zookeeper 教程</a></li><li><a title="设计模式" href="../design-pattern/design-pattern-tutorial.html">设计模式</a></li><li><a title="正则表达式" href="../regexp/regexp-tutorial.html">正则表达式</a></li><li><a title="Maven 教程" href="../maven/maven-tutorial.html">Maven 教程</a></li><li><a title="Verilog 教程" href="../w3cnote/verilog-tutorial.html">Verilog 教程</a></li><li><a title="ASP 教程" href="../asp/asp-tutorial.html">ASP 教程</a></li><li><a title="AppML 教程" href="../appml/appml-tutorial.html">AppML 教程</a></li><li><a title="VBScript 教程" href="../vbscript/vbscript-tutorial.html">VBScript 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据库</a><ul class="double-li"><li><a title="SQL 教程" href="../sql/sql-tutorial.html">SQL 教程</a></li><li><a title="MySQL 教程" href="../mysql/mysql-tutorial.html">MySQL 教程</a></li><li><a title="PostgreSQL 教程" href="../postgresql/postgresql-tutorial.html">PostgreSQL 教程</a></li><li><a title="SQLite 教程" href="../sqlite/sqlite-tutorial.html">SQLite 教程</a></li><li><a title="MongoDB 教程" href="../mongodb/mongodb-tutorial.html">MongoDB 教程</a></li><li><a title="Redis 教程" href="../redis/redis-tutorial.html">Redis 教程</a></li><li><a title="Memcached 教程" href="../Memcached/Memcached-tutorial.html">Memcached 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据分析</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="NumPy 教程" href="../numpy/numpy-tutorial.html">NumPy 教程</a></li><li><a title="Pandas 教程" href="../pandas/pandas-tutorial.html">Pandas 教程</a></li><li><a title="Matplotlib 教程" href="../matplotlib/matplotlib-tutorial.html">Matplotlib 教程</a></li><li><a title="Scipy 教程" href="../scipy/scipy-tutorial.html">Scipy 教程</a></li><li><a title="R 教程" href="../r/r-tutorial.html">R 教程</a></li><li><a title="Julia 教程" href="../julia/julia-tutorial.html">Julia 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 移动端</a><ul class="double-li"><li><a title="Android 教程" href="../w3cnote/android-tutorial-intro.html">Android 教程</a></li><li><a title="Swift 教程" href="../swift/swift-tutorial.html">Swift 教程</a></li><li><a title="jQuery Mobile 教程" href="../jquerymobile/jquerymobile-tutorial.html">jQuery Mobile 教程</a></li><li><a title="ionic 教程" href="../ionic/ionic-tutorial.html">ionic 教程</a></li><li><a title="Kotlin 教程" href="../kotlin/kotlin-tutorial.html">Kotlin 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> XML 教程</a><ul class="double-li"><li><a title="XML 教程" href="../xml/xml-tutorial.html">XML 教程</a></li><li><a title="DTD 教程" href="../dtd/dtd-tutorial.html">DTD 教程</a></li><li><a title="XML DOM 教程" href="../dom/dom-tutorial.html">XML DOM 教程</a></li><li><a title="XSLT 教程" href="../xsl/xsl-tutorial.html">XSLT 教程</a></li><li><a title="XPath 教程" href="../xpath/xpath-tutorial.html">XPath 教程</a></li><li><a title="XQuery 教程" href="../xquery/xquery-tutorial.html">XQuery 教程</a></li><li><a title="XLink 教程" href="../xlink/xlink-tutorial.html">XLink 教程</a></li><li><a title="XPointer 教程" href="../xlink/xlink-tutorial.html">XPointer 教程</a></li><li><a title="XML Schema 教程" href="../schema/schema-tutorial.html">XML Schema 教程</a></li><li><a title="XSL-FO 教程" href="../xslfo/xslfo-tutorial.html">XSL-FO 教程</a></li><li><a title="SVG 教程" href="../svg/svg-tutorial.html">SVG 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> ASP.NET</a><ul class="double-li"><li><a title="ASP.NET 教程" href="../aspnet/aspnet-tutorial.html">ASP.NET 教程</a></li><li><a title="C# 教程" href="../csharp/csharp-tutorial.html">C# 教程</a></li><li><a title="Web Pages 教程" href="../aspnet/webpages-intro.html">Web Pages 教程</a></li><li><a title="Razor 教程" href="../aspnet/razor-intro.html">Razor 教程</a></li><li><a title="MVC 教程" href="../aspnet/mvc-intro.html">MVC 教程</a></li><li><a title="Web Forms 教程" href="../aspnet/aspnet-intro.html">Web Forms 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> Web Service</a><ul class="double-li"><li><a title="Web Service 教程" href="../webservices/webservices-tutorial.html">Web Service 教程</a></li><li><a title="WSDL 教程" href="../wsdl/wsdl-tutorial.html">WSDL 教程</a></li><li><a title="SOAP 教程" href="../soap/soap-tutorial.html">SOAP 教程</a></li><li><a title="RSS 教程" href="../rss/rss-tutorial.html">RSS 教程</a></li><li><a title="RDF 教程" href="../rdf/rdf-tutorial.html">RDF 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 开发工具</a><ul class="double-li"><li><a title="Eclipse 教程" href="../eclipse/eclipse-tutorial.html">Eclipse 教程</a></li><li><a title="Git 教程" href="../git/git-tutorial.html">Git 教程</a></li><li><a title="Svn 教程" href="../svn/svn-tutorial.html">Svn 教程</a></li><li><a title="Markdown 教程" href="../markdown/md-tutorial.html">Markdown 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 网站建设</a><ul class="double-li"><li><a title="HTTP 教程" href="../http/http-tutorial.html">HTTP 教程</a></li><li><a title="网站建设指南" href="../web/web-buildingprimer.html">网站建设指南</a></li><li><a title="浏览器信息" href="../browsers/browser-information.html">浏览器信息</a></li><li><a title="网站主机教程" href="../hosting/hosting-tutorial.html">网站主机教程</a></li><li><a title="TCP/IP 教程" href="../tcpip/tcpip-tutorial.html">TCP/IP 教程</a></li><li><a title="W3C 教程" href="../w3c/w3c-tutorial.html">W3C 教程</a></li><li><a title="网站品质" href="../quality/quality-tutorial.html">网站品质</a></li></ul></li></ul>            </div>
    
    </div>
    </div>
    <br>
    
    <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here">
            <a href="javascript:void(0);">Advertisement</a>
        </div>
        <div class="re-600160" id="sidebar-right-re">
                <script async src=""></script>
        <!-- 侧栏1 -->
        <ins class="adsbygoogle"
             style="display:inline-block;width:160px;height:600px"
             data-ad-client="ca-pub-5751451760833794"
             data-ad-slot="4106274865"></ins>
        <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
                </div>
    </div>
</div></div>

</div>

<script>
var aid = 9510;
function coll() {
	$.post( '/wp-content/themes/runoob/option/user/userinfo.php', {aid:aid, action:"collarticle", opt:'add'},function( data ) {
		if(data.error==0) {
			$("#content").find("h1:first").find("a").attr("href","javascript:void(0);");
			$("#content").find("h1:first").find("img").attr("src","http://www.runoob.com/wp-content/themes/runoob/assets/img/coll2.png").css({width:32+"px",height:32+"px"});
		}
		alert(data.msg);
	},'json');
}
</script>


<!-- 反馈对话框开始 -->
<script src=""></script>
<link rel="stylesheet" href="../0/feedback.css?1.0" />
<script type="text/javascript">
$.feedback({
    ajaxURL: '/feedback/runoob_feedback.php',
	html2canvasURL: '/wp-content/themes/runoob/assets/feedback/stable/2.0/html2canvas.js',
	onClose: function () {
         window.location.reload();
    }
});
</script>
<!-- 反馈对话框结束 -->
<button class="feedback-btn feedback-btn-gray">反馈/建议</button>
<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>